<?php
namespace frontend\controllers;

use Yii;
use common\models\Article;
use common\models\Game;
use common\models\GameWithType;
use common\models\GameVersion;
use yii\helpers\BaseJson;

/**
 * 测试控制器
 *
 * @author jois
 */
class TestController extends BaseController
{

    public function actionIndex()
    {
        header("Content-type:text/html;charset=utf-8");
        // $res = Yii::$app->db->createCommand('select game_id,game_name,game_type from `2013_game` limit 1500,500')->queryAll();
        $res = Yii::$app->db->createCommand('select game_id,game_name,game_type from 2013_game a where game_id not in(select DISTINCT a.game_id from game_with_type a)')->queryAll();
        foreach ($res as $item) {
            $game_id = (int) $item['game_id'];
            $game_name = $item['game_name'];
            $types = json_decode($item['game_type'], true);
            if (is_array($types)) {
                foreach ($types as $key => $value) {
                    if (! empty($key)) {
                        $temp = GameWithType::find()->where("game_id={$game_id} and type_id={$key}")->one();
                        if (is_null($temp)) {
                            $game_with_type = new GameWithType();
                            $game_with_type->game_id = $game_id;
                            $game_with_type->game_name = $game_name;
                            $game_with_type->type_id = $key;
                            $game_with_type->type_name = $value;
                            $game_with_type->save();
                            echo $game_id . '--OK<br>';
                            // var_dump($game_with_type);die();
                        }
                    }
                }
            }
        }
        die();
    }
}